<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		<img id="img" src="img/1.jpg" width="1280" height="640">
		<input type="button" id="btn" value="后退" />
		<script>
			setInterval(fun, 2000);
			// 如果定义在方法中会重置为1
			var i = 1;

			function fun() {
				var img = document.getElementById("img");

				img.src = "img/" + (String(i++)) + ".jpg";
				if (i > 9) {
					i = 1;
				}
			}
			var btn = document.getElementById('btn');
			btn.onclick = function() {
				history.back();
			}
		</script>
	</body>
</html>
